
***Replication codes for "China's Low-Productivity Innovation Drive: Evidence from Patents"***


//set the path for the replication files folder
global wd "INSERT THE PATH OF THE REPLICATION FILES FOLDER" 
cd "$wd"



*******replicate results in the main texts********************

//Figure 1
use "$wd\national_yearly.dta", clear

twoway  (bar patent_count year if year<=2014, color(navy))(function y=750000, range(2005.98 2006.02) droplines(2006) lcolor(maroon)), ///
xlabel(1990(5)2010 2014) ylabel(0 "0" 250000 "250,000" 500000 "500,000" 750000 "750,000")  ///
xtitle("") ytitle("Number of Patents", axis(1)) ///
legend(off) graphregion(color(white)) ///
 text(780000 2004 "Launch of national campaign to" "promote indigenous innovation", j(left) size(small))



 
//Figure 3
use "$wd\national_yearly.dta", clear

twoway (connected patent_secondisnovel year if year<=2014, color(navy)) (function y=0.13, range(2005.98 2006.02) droplines(2006) lcolor(maroon)), ///
xlabel(1990(5)2010 2014) ylabel(0 "0" 0.02 "2"  0.04 "4"  0.06 "6"  0.08 "8" 0.1 "10"  0.12 "12") ///
xtitle("") ytitle("Proportion of Novel Patents (%)") ///
legend(off) graphregion(color(white)) ///
 text(0.13 2004 "Launch of national campaign to" "promote indigenous innovation", j(left) size(small))


		

//Figure 6
use "$wd\main.dta", clear

foreach i of numlist 1990(1)2012 {
	gen govrevenueg_cls`i'=govrevenueg_cls*(year==`i')
}

xi: xtreg f.lnpatent_count govrevenueg_cls1990-govrevenueg_cls2012 lngdppc popugrowth fdishare gender age edu minority lngdp_province i.year if year<=2012, fe r

postutil clear
postfile yearlyeffect year beta ci_l95 ci_u95 using yearlyeffect_figure6.dta, replace
	foreach num of numlist 1991(1)2012 {
		local cil95 = _b[govrevenueg_cls`num'] - _se[govrevenueg_cls`num']*invttail(100, 0.025)
		local ciu95 = _b[govrevenueg_cls`num'] + _se[govrevenueg_cls`num']*invttail(100, 0.025)
		post yearlyeffect (`num') (_b[govrevenueg_cls`num']) (`cil95') (`ciu95')
		}
postclose yearlyeffect

preserve
use yearlyeffect_figure6,clear
twoway (rarea ci_u95 ci_l95 year, color(gs12) lwidth(none)) (connected beta year, msize(s) mcolor(navy) lcolor(navy)) (function y=2006, range(-0.2 0.2) lcolor(maroon) horizontal), ///
			xlabel(1990(5)2010) xline(2006, lcolor(maroon))  ylabel(-0.2 -0.1 0 0.1 0.2) legend(label(1 95% CI) label(2 estimates) order(1 2)) xtitle("") ytitle("coefficients") graphregion(color(white))
restore




//Figure 7
use "$wd\main.dta", clear

foreach i of numlist 1990(1)2012 {
	gen govrevenueg_cls`i'=govrevenueg_cls*(year==`i')
}

xi: xtreg f.patent_novelshare govrevenueg_cls1990-govrevenueg_cls2012 lngdppc popugrowth fdishare gender age edu minority lngdp_province i.year if year<=2012, fe r

postutil clear
postfile yearlyeffect year beta ci_l95 ci_u95 using yearlyeffect_figure7.dta, replace
	foreach num of numlist 1991(1)2012 {
		local cil95 = _b[govrevenueg_cls`num'] - _se[govrevenueg_cls`num']*invttail(100, 0.025)
		local ciu95 = _b[govrevenueg_cls`num'] + _se[govrevenueg_cls`num']*invttail(100, 0.025)
		post yearlyeffect (`num') (_b[govrevenueg_cls`num']) (`cil95') (`ciu95')
		}
postclose yearlyeffect

preserve
use yearlyeffect_figure7,clear
twoway (rarea ci_u95 ci_l95 year, color(gs12) lwidth(none)) (connected beta year, msize(s) mcolor(navy) lcolor(navy)) (function y=2006, range(-2 2) lcolor(maroon) horizontal), ///
			xlabel(1990(5)2010) xline(2006, lcolor(maroon)) ylabel(-2(1)2) legend(label(1 95% CI) label(2 estimates) order(1 2)) xtitle("") ytitle("coefficients") graphregion(color(white)) 
restore




//Table 3
use "$wd\main.dta", clear

logout, save("$wd\Table3") word replace dec(3):  tabstat lnpatent_count patent_novelshare govrevenueg_cls post lngdppc popugrowth fdishare gender age edu minority lngdp_province if year<=2012, stat(mean median sd n) col(statistics)




//Table 4
use "$wd\main.dta", clear

gen govrevenueg_cls_post=govrevenueg_cls*post

estimates clear

//all patents
xi: xtreg f.lnpatent_count govrevenueg_cls_post govrevenueg_cls i.year if year<=2012, fe r
est store a1

xi: xtreg f.lnpatent_count govrevenueg_cls_post govrevenueg_cls lngdppc popugrowth fdishare gender age edu minority lngdp_province i.year if year<=2012, fe r
est store a2

xi: xtreg f.patent_novelshare govrevenueg_cls_post govrevenueg_cls lngdppc popugrowth fdishare gender age edu minority lngdp_province i.year if year<=2012, fe r
est store a3

outreg2 [a*] using "$wd\Table4.xls", excel dec(3) nocons drop(_Iyear* o._I*) sortvar(govrevenueg_cls_post govrevenueg_cls lngdppc popugrowth fdishare gender age edu minority lngdp_province)  addtext(City FE, YES, Year FE, YES)  ///
		addnote(Standard errors in parentheses are clustered at the city level.)  replace	




		
*******replicate results in the Appendix********************


//Figure A1
use "$wd\main.dta", clear

duplicates drop provincecode year,force
histogram govrevenueg_cls_nosd, width(0.01) kdensity  xtitle("Within-province Standard Deviation of Fiscal Revenue Growth*(-1)") graphregion(color(white)) 




//Figure A2
use "$wd\main.dta", clear

gen govrevenueg_cls_post=govrevenueg_cls*post

foreach i of numlist 1990(1)2012 {
	gen lngdppc`i'=lngdppc*(year==`i')
}


xi: xtreg f.lnpatent_count govrevenueg_cls_post govrevenueg_cls lngdppc1990-lngdppc2012 popugrowth fdishare gender age edu minority lngdp_province i.year if year<=2012, fe r

postutil clear
postfile yearlyeffect year beta ci_l95 ci_u95 using yearlyeffect_figurea2.dta, replace
	foreach num of numlist 1991(1)2012 {
		local cil95 = _b[lngdppc`num'] - _se[lngdppc`num']*invttail(100, 0.025)
		local ciu95 = _b[lngdppc`num'] + _se[lngdppc`num']*invttail(100, 0.025)
		post yearlyeffect (`num') (_b[lngdppc`num']) (`cil95') (`ciu95')
		}
postclose yearlyeffect

preserve
use yearlyeffect_figurea2,clear
twoway (rarea ci_u95 ci_l95 year, color(gs12) lwidth(none)) (connected beta year, msize(s) mcolor(navy) lcolor(navy)) (function y=2006, range(-0.6 0.6) lcolor(maroon) horizontal), ///
			xlabel(1990(5)2010) xline(2006, lcolor(maroon))  ylabel(-0.6 -0.4 -0.2 0  0.2 0.4 0.6) legend(label(1 95% CI) label(2 estimates) order(1 2)) xtitle("") ytitle("coefficients") graphregion(color(white)) 
restore





//Table A2
use "$wd\main.dta", clear

duplicates drop provincecode year,force
bys year (govrevenueg_cls_nosd): gen rank=_n
gsort year -govrevenueg_cls_nosd
list year provincecode govrevenueg_cls_nosd if year==2006

	

	

//Table A3
use "$wd\main.dta", clear

gen govrevenueg_rank_post=govrevenueg_rank*post

estimates clear 

xi: xtreg f.lnpatent_count govrevenueg_rank_post govrevenueg_rank i.year if year<=2012, fe r
est store a1

xi: xtreg f.lnpatent_count govrevenueg_rank_post govrevenueg_rank lngdppc popugrowth fdishare gender age edu minority lngdp_province i.year if year<=2012, fe r
est store a2

outreg2 [a*] using "$wd\TableA3.xls", excel dec(3) nocons drop(_Iyear* o._I*) sortvar(govrevenueg_rank_post govrevenueg_rank lngdppc popugrowth fdishare gender age edu minority lngdp_province)  addtext(City FE, YES, Year FE, YES)  ///
		addnote(Standard errors in parentheses are clustered at the city level.)  replace	

		
//Table A4
use "$wd\main.dta", clear

gen govrevenueg_rank_post=govrevenueg_rank*post

estimates clear 

xi: xtreg f.patent_novelshare govrevenueg_rank_post govrevenueg_rank i.year, fe r
est store a1

xi: xtreg f.patent_novelshare govrevenueg_rank_post govrevenueg_rank lngdppc popugrowth fdishare gender age edu minority lngdp_province i.year, fe r
est store a2

outreg2 [a*] using "$wd\TableA4.xls", excel dec(3) nocons drop(_Iyear* o._I*) sortvar(govrevenueg_rank_post govrevenueg_rank lngdppc popugrowth fdishare gender age edu minority lngdp_province)  addtext(City FE, YES, Year FE, YES)  ///
		addnote(Standard errors in parentheses are clustered at the city level.)  replace	

		

//Table A5
use "$wd\main.dta", clear

asdoc pwcorr lnpatent_count patent_novelshare govrevenueg_cls post lngdppc popugrowth fdishare gender age edu minority lngdp_province if year<=2012, dec(3) star(all) save(${wd}\TableA5) replace

